package com.newcoin.xgb.controller;

import com.newcoin.xgb.dto.QueryParameterDto;
import com.newcoin.xgb.dto.RechargeDto;
import com.newcoin.xgb.dto.RechargeReportDto;
import com.newcoin.xgb.dto.WithdrawDto;
import com.newcoin.xgb.entity.*;
import com.newcoin.xgb.po.*;
import com.newcoin.xgb.service.XgbAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/xgb")
@Api(description = "乐刷账户接口")
@Slf4j
public class XgbAccountController {

    @Autowired
    private XgbAccountService service;


    @ApiOperation(value = "获取账户信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getAccount")
    public Result<XgbAccount> getAccount(QueryParameterDto queryParameterDto) {
        try {
            return service.getAccount(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<XgbAccount> result = new Result();
            result.setCode(500);
            result.setMessage("获取信息失败");
            return result;
        }
    }

    @ApiOperation(value = "获取充值记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getRecharge")
    public Result<RechargePo> getRecharge(QueryParameterDto queryParameterDto) {
        try {
            return service.getRecharge(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<RechargePo> result = new Result();
            result.setCode(500);
            result.setMessage("获取充值记录失败");
            return result;
        }
    }

    @ApiOperation(value = "提交充值凭证")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "url", value = "凭证路径", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "amount", value = "充值金额", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @PostMapping(value = "/submitRecharge")
    public Result submitRecharge(RechargeDto rechargeDto){
        try {
            return service.submitRecharge(rechargeDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<RechargePo> result = new Result();
            result.setCode(500);
            result.setMessage("获取充值记录失败");
            return result;
        }
    }

    @ApiOperation(value = "获取提现记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getWithdraw")
    public Result<WithdrawPo> getWithdraw(QueryParameterDto queryParameterDto) {
        try {
            return service.getWithdraw(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<WithdrawPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取提现记录失败");
            return result;
        }
    }

    @ApiOperation(value = "获取奖金记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getBonus")
    public Result<BonusRecordPo> getBonus(QueryParameterDto queryParameterDto) {
        try {
            return service.getBonus(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<BonusRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取奖金记录失败");
            return result;
        }
    }

    @ApiOperation(value = "获取抢单记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getGrabOrdersRecord")
    public Result<GrabOrdersRecordPo> getGrabOrdersRecord(QueryParameterDto queryParameterDto) {
        try {
            return service.getGrabOrdersRecord(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<GrabOrdersRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取抢单记录失败");
            return result;
        }
    }

    @ApiOperation(value = "获取已提交订单")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getCommittedOrders")
    public Result<GrabOrdersRecordPo> getCommittedOrders(QueryParameterDto queryParameterDto) {
        try {
            return service.getCommittedOrders(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<GrabOrdersRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取提交订单失败");
            return result;
        }
    }


    @ApiOperation(value = "获取未提交订单")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "type", value = "类型", required = true, dataType = "int"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getUncommittedOrders")
    public Result<GrabOrdersRecordPo> getUncommittedOrders(QueryParameterDto queryParameterDto) {
        try {
            return service.getUncommittedOrders(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<GrabOrdersRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取未提交订单失败");
            return result;
        }
    }

/////////////////////////////////////////////////////////////////
    @ApiOperation(value = "获取代理分佣记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getProxy")
    public Result<BonusRecordPo> getProxy(QueryParameterDto queryParameterDto) {
        try {
            return service.getProxy(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<BonusRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取代理分佣记录失败");
            return result;
        }
    }
///////////////////////////////////////////////////////////////////////////
    @ApiOperation(value = "获取理财收益记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getIncomeRecord")
    public Result<BonusRecordPo> getIncomeRecord(QueryParameterDto queryParameterDto) {
        try {
            return service.getIncomeRecord(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<BonusRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取理财收益记录失败");
            return result;
        }
    }

    @ApiOperation(value = "获取理财购买记录")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "page", value = "页", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getAssetRecord")
    public Result<AssetRecordPo> getAssetRecord(QueryParameterDto queryParameterDto) {
        try {
            return service.getAssetRecord(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<AssetRecordPo> result = new Result();
            result.setCode(500);
            result.setMessage("获取理财购买记录失败");
            return result;
        }
    }

    @ApiOperation(value = "提现")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "amount", value = "金额", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "bankInfoId", value = "银行信息ID", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "payPwd", value = "交易密码", required = true, dataType = "String")
            }
    )
    @PostMapping(value = "/withdraw")
    public Result withdraw(WithdrawDto withdrawDto) {
        try {
            return service.withdraw(withdrawDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result result = new Result();
            result.setCode(500);
            result.setMessage("提现失败");
            return result;
        }
    }

//    @ApiOperation(value = "获取vip信息")
//    @ApiImplicitParams(
//            {
//                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
//                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
//                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
//            }
//    )
//    @GetMapping(value = "/getOptionalVip")
//    public Result<OptionalVipPo> getOptionalVip(QueryParameterDto queryParameterDto) {
//        try {
//            return service.getOptionalVip(queryParameterDto);
//        } catch (Exception e) {
//            log.error(e.getMessage());
//            Result<OptionalVipPo> result = new Result();
//            result.setCode(500);
//            result.setMessage("获取vip信息失败");
//            return result;
//        }
//    }

    @ApiOperation(value = "获取余额")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getBalance")
    public Result<BigDecimal> getBalance(QueryParameterDto queryParameterDto) {
        try {
            return service.getBalance(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<BigDecimal> result = new Result();
            result.setCode(500);
            result.setMessage("获取余额失败");
            return result;
        }
    }

    @ApiOperation(value = "获取充值地址")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "token", value = "token", required = true, dataType = "String"),
                    @ApiImplicitParam(name = "", value = "忽略非必填参数", required = false)
            }
    )
    @GetMapping(value = "/getRechargeAddress")
    public Result<Map<String, Object>> getRechargeAddress(QueryParameterDto queryParameterDto) {
        try {
            return service.getRechargeAddress(queryParameterDto);
        } catch (Exception e) {
            log.error(e.getMessage());
            Result<Map<String, Object>> result = new Result();
            result.setCode(500);
            result.setMessage("获取失败");
            return result;
        }
    }
}
